﻿// 2023/5/12: 首个版本
// 2024/7/1: 基于spadas9
// 2025/6/26: parseDirectly处理一个包中有多个SomeIP帧的情况。新增splitSomeIPFrames。新增SomeIPSplitter类

#ifndef ETHERNET_PARSER_H
#define ETHERNET_PARSER_H

#include "spadas.h"

#define MAX_SOME_IP_FRAME_COUNT 96

namespace eth_parser
{
	using namespace spadas;

	class EthernetParser
	{
	public:
		static Bool parse(Binary& rawPacket, UInt channel, Array<Enum<BusChannelType> >& typeHints, Enum<BusChannelType>& type, UInt& id);
		static Bool parseDirectly(Binary& rawPacket, Enum<BusChannelType> type, UInt& id);
		static void splitSomeIPFrames(Binary& rawPacket, Array<UInt>& someIPStartIndicesBuffer, BinarySpan& header, UInt& ipv4StartIndex, Array<BinarySpan>& someIPFrames, UInt& validCount);

	private:
		static Word parseBigEndianWord(Byte *rawData, UInt offset);
		static UInt parseBigEndianUInt(Byte *rawData, UInt offset);
		static Bool parseSomeIP(Byte *rawData, UInt rawSize, UInt& someIPStartIndex);
		static Bool parseSomeIP(Byte *rawData, UInt rawSize, Array<UInt> someIPStartIndicesBuffer, UInt& validIndexCount, UInt& ipv4StartIndex);
	};

	class SomeIPSplitter : public Object<class SomeIPSplitterVars>
	{
	public:
		SomeIPSplitter();
		Array<SessionBusRawData> split(SessionBusRawData someIPData);
	};
}

#endif